import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import * as path from 'path'


const getAbsPath = (url: string) => path.resolve(__dirname, url)


// https://vite.dev/config/
export default defineConfig(({mode})=>{

  const APP_API: string = loadEnv(mode,process.cwd()).VITE_APP_API;
  console.log("APP_API:",APP_API)
  const API_TOKEN: string = loadEnv(mode,process.cwd()).VITE_API_TOKEN_KEY;
  console.log("API_TOKEN:",API_TOKEN)

  return {
    server:{
      base:'./',
      port:5001,
      // proxy: {
      //   // 选项写法
      //   '/api': {
      //     target: APP_API,  //VITE_APP_API
      //     changeOrigin: true,
      //     rewrite: (path) => {
      //       return path.replace(/^\/api/, '');
      //     },
      //   },
      // },
    },
    plugins: [
      vue(),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ],
      }),
    ],
    css: {
      preprocessorOptions: {
        less: {
          additionalData: '@import "@/styles/variables.less";',
        },
      },
    },
    resolve:{
      alias:{
        '@': getAbsPath('./src'),
        '@components': getAbsPath('./src/components'),
        '@utils': getAbsPath('./src/utils'),
        '@config': getAbsPath('./src/config'),
        '@views': getAbsPath('./src/views'),
        // '@build': getAbsPath('./build'),
      },
      extensions:['.vue','.ts','.js','.json','.tsx','.jsx']
    },
    
  }  
})
